package com.example;

import org.elephantt.webby.*;
import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;

import javax.servlet.ServletConfig;

public class AppDispatcherServlet extends DispatcherServlet {
  private static final long serialVersionUID = 2280812403107058276L;

  @Override
  public Dispatcher createDispatcher(ServletConfig config) {
    RouteRequestMapper mapper = new RouteRequestMapper();
    mapper.addRoute(HttpMethod.GET, "/", new HomeController(), "index");

    Dispatcher dispatcher = new Dispatcher(mapper);

    Configuration configuration = new Configuration();
    configuration.setObjectWrapper(new DefaultObjectWrapper());
    configuration.setTagSyntax(Configuration.SQUARE_BRACKET_TAG_SYNTAX);
    configuration.setServletContextForTemplateLoading(config.getServletContext(), "/templates");
    dispatcher.setDefaultResponder(new FtlViewResponder(configuration, "text/html"));

    return dispatcher;
  }
}